/*   
    Copyright (C) 2009 Galaktika Corporation ZAO

    This file is a part of Galaktika.BusinessMonitor
 
    Galaktika.BusinessMonitor is a free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
      
    You should have received a copy of the GNU General Public License
    along with Galaktika.BusinessMonitor.  If not, see <http://www.gnu.org/licenses/>.
  
    If GPL v.3 is not suitable for your products or company,
    Galaktika Corp provides Galaktika.BusinessMonitor under a flexible commercial license
    designed to meet your specific usage and distribution requirements.
    If you have already obtained a commercial license from Galaktika Corp,
    you can use this file under those license terms.
*/

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;

namespace Test.Extension
{
    using Galaktika.BI.Extensibility;
    using Galaktika.BI.Extensibility.Design;
    using Test.Extension.Commands;
    internal class TestExtension : IExtension
    {
        public TestExtension()
        {
        }

        #region IExtension Members

        public string Name
        {
            get { return "Tets Extension v1.1"; }
        }

        public string Description
        {
            get { return "It's a very very usefull extension."; }
        }

        public Image Image32
        {
            get { return Resources.GetImage(Resources.TEST_EXT_32); }
        }

        public string Vendor
        {
            get
            {
                return "Tester";
            }
        }

        public string Version
        {
            get
            {
                return "1.0";
            }
        }

        private bool m_Enabled = true;
        public bool Enabled
        {
            get
            {
                return m_Enabled;
            }
            set
            {
                m_Enabled = value;
            }
        }

        IServiceProvider m_Services;
        private ToolboxItem m_TestItem;
        public void Initialize(IServiceProvider services)
        {
            m_Services = services;
            ICommandService cmd = (ICommandService)services.GetService(typeof(ICommandService));
            if (cmd != null)
            {
                cmd.RegisterCommands(this, new ICommand[] { new TestCommand() });
            }
            IEnvDTEService env = (IEnvDTEService)services.GetService(typeof(IEnvDTEService));
            if (env != null)
            {
                env.RegisterManagers(this, new IIDEManager[] 
                { 
                    new Managers.TestManager()
                });
            }
            IToolboxService tb = (IToolboxService)services.GetService(typeof(IToolboxService));
            if (tb != null)
            {
                m_TestItem = new CustomToolboxItem(typeof(Button));
                tb.AddToolboxItem(m_TestItem, "Test items");
            }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            IEnvDTEService env = (IEnvDTEService)m_Services.GetService(typeof(IEnvDTEService));
            if (env != null)
            {
                env.UnRegisterManagers(this);
            }
            IToolboxService tb = (IToolboxService)m_Services.GetService(typeof(IToolboxService));
            if (tb != null)
            {
                tb.RemoveToolboxItem(m_TestItem, "Test items");
            }
            //MessageBox.Show("TestExtension disposed");
        }

        #endregion
    }
}
